/***********************
  * class resource, cache the file
  *
  * created by dirkcai
  *********************/

#ifndef RESOURCE_H
#define RESOURCE_H

#include <map>
#include <iterator>
#include <string>
using namespace std;

class Buffer;

class ResourceItem
{
public:
	ResourceItem( const string type, char * buf, int buflen );
	~ResourceItem();
	Buffer * GetBuffer();
	string GetType();
	int GetLength();
private:
	Buffer * m_ptBuffer;
	string m_strType;
};

class TextResourceChecker
{
public:
	static int Config( string * texttypes, int size );
	static bool IsTextResource( string type );
	~TextResourceChecker();
	int Init( string * texttypes, int size );
	bool IsTextType( string type );
private:
	TextResourceChecker();
	
private:
	static TextResourceChecker m_obj;
	string * m_textTypes;
	int m_textTypesSize;
};

class ResourceMap
{
public:
	ResourceMap( const char * psDirpath );
	~ResourceMap();
	ResourceItem * GetResource( const string * path );
private:
	map<string, ResourceItem*> m_map;
	string m_strDirpath;
};

class Resource
{
public:
	static int Config( const char * psDirpath );
	static ResourceItem * GetResource( const char * path );
	static ResourceItem * GetResource( const string * path );
	static int DestroyResource();
private:
	Resource(){};
private:
	static ResourceMap * m_ptMap;	
};

#endif
